package org.hong.microservice.rs1.controller;

import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by victor on 2020/3/30 19:46.
 */
@RestController
public class SimpleController {
    @GetMapping("/whoami")
    public String whoami(@AuthenticationPrincipal(expression = "name") String name) {
        return name;
    }

    @GetMapping("/")
    public String index(@AuthenticationPrincipal OAuth2AuthenticatedPrincipal principal) {
        return String.format("Hello, %s, %s!", principal.getName(), principal.getAttribute("sub"));
    }

    @GetMapping("/message")
    public String message() {
        return "secret message";
    }
}
